﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace PlantsVsZombies
{
    public enum GhostStatus { Move,Attack, Die};

    public abstract class Ghost : Character
    {
        private GhostStatus _ghostStatus;
        private float _deltaMove;
        protected int Blood;
        protected int AppearTime;// thoi gian ma xuat hien

        public GhostStatus GhostStatus
        {
            get { return _ghostStatus; }
            set { _ghostStatus = value; }
        }

        public float DeltaMove
        {
            get { return _deltaMove; }
            set { _deltaMove = value; }
        }

        public bool IsCollisionPlant(Plant other)
        {
            float d = Math.Abs(this.Position.X - other.Position.X);
            if ((d <= other.Size.X) && Math.Abs(this.Position.Y - other.Position.Y) < 20.0f)
            {
                this.GhostStatus = GhostStatus.Attack;
                return true;
            }
            return false;
        }
        public bool IsCollisionVehicle(Vehicle other)
        {
            float d = Math.Abs(this.Position.X - other.Position.X);
            if ((d <= 0.5*other.Size.X) && Math.Abs(this.Position.Y - other.Position.Y) < 20.0f)
            {
                this.GhostStatus = GhostStatus.Die;
                return true;
            }
            return false;
        }

        public abstract void EatPlant(Plant plant);
        public Boolean IsHitBullet(Sprite bullet)
        {
            if( this.Position.X < bullet.Position.X && bullet.Position.X < this.Position.X + this.Size.X)
                if( this.Position.Y < bullet.Position.Y && bullet.Position.Y < this.Position.Y + this.Size.Y)
                    if(bullet.Visible)
                    {
                        if (this.Blood > 0)
                            this.Blood--;
                        else
                        {
                            this.Visible = false;
                            this.Position = new Vector2(-500,-500);
                        }
                        return true;
                    }

            return false;
        }
        public override void Update(GameTime gameTime)
        {
            // toi thoi gian moi dc xuat hien
            if (gameTime.TotalGameTime.TotalSeconds < AppearTime)
                this.Visible = false;
            else
            {
                this.Visible = true;
                base.Update(gameTime);
            }
            
        }
      
    }
}
